Blog

How to move WSL distros to a different drive on Windows 11, 10

  • To move a WSL distro to another hard drive on Windows 11 (or 10), open Settings > Apps > Installed apps, choose the “Move” option from the Linux installation menu, and select the new drive.
  • Alternatively, you can also open Command Prompt (admin) and run the wsl --manage DISTRO --move NEW-DRIVE command or use the export and import commands.

On the Windows Subsystem for Linux (WSL), you cannot specify the location where you can install your Linux distributions. However, it’s possible to move an already configured distro to another drive, and in this guide, I will outline the steps to complete this configuration.

On Windows 11 (or 10), WSL has multiple components distributed across the operating system installation (especially inside the “System32” folder), which makes it virtually impossible to install or move this setup along with the Linux distributions to another, nor you can’t configure a new storage location to install distros.

However, you can transfer your Linux distributions to a new location in multiple ways. For example, you can use the WSL --move command to relocate the existing distribution or accomplish the same configuration by exporting and importing a Linux installation from another drive using the --import command. If you want an even easier way, it’s also possible to move the existing Windows Subsystem for Linux distribution using the move functionality available in the Settings app.

In this guide, I will outline the steps to move Linux distros using WSL to another location on Windows 11 (or 10).

Change Linux distro install drive on WSL using Settings

To move a WSL distro to another folder location using the Settings app, use these steps:

  1. Open Start.

  2. Search for Command Prompt, right-click the top result, and choose the Run as administrator option.

  3. Type the following command to shutdown any running distribution of Linux and press Enter:

    wsl --shutdown

  4. Open Settings.

  5. Click on Apps.

  6. Click the Installed apps page.

  7. Open the menu button for the distro and choose the Move option.

    Windows 11 Settings move option for apps

  8. Choose the drive to relocate the Linux distribution.

  9. Click the Move button.

    WSL distro move to new drive from Settings

After you complete the steps, the files to run the WSL distro will be relocated to the new drive.

Change Linux distro install drive on WSL using Move command

To move a WSL distro to another drive, use these steps:

  1. Open Start.

  2. Search for Command Prompt, right-click the top result, and choose the Run as administrator option.

  3. Type the following command to view the distros already installed on your computer and press Enter:

    wsl --list --all
  4. Type the following command to shutdown any running distribution of Linux and press Enter:

    wsl --shutdown
  5. Type the following command to move a WSL distro to another drive and press Enter:

    wsl --manage Ubuntu --move F:\WSL\Ubuntu

    WSL move distro new drive command

    In the command, change “Ubuntu” for name of the distro and “F:\WSL\Ubuntu” for the new drive location to store the Linux installation.

  6. Type the following command to run the Linux distribution from the new location and press Enter:

    wsl -d Ubuntu

    In the command, change “Ubuntu” to the actual name of the Linux installation.

Once you complete the steps, the distro will run from the new drive location.

If you receive the “Failed to attach disk ‘F:\Path\to\ext4.vhdx’ to WSL2: Access is denied. Error code: Wsl/Service/CreateInstance/MountVhd/HCS/E_ACCESSDENIED” error, run the wsl --shutdown command and then run the wsl -d DISTRO-NAME command. Usually, this error may occur if you’re trying to start the distribution from the Start menu after the move to the new location.

If you have multiple Linux distributions, I recommend you create a main folder (Ctrl + Shift + N) on the new hard drive and a separate folder for each WSL distro you want to host inside this folder since each distribution is installed inside a “.vhdx” file with the same “ext4” name, and you cannot have two files with the same name.

For reference, when you install a Linux distribution using WSL, the system installs the package in the %USERPROFILE%\AppData\Local\Packages\ location, which is the same place the operating system installs the packages and other apps that come from the Microsoft Store. Also, the virtual drive containing the distro files is located inside the package name, more specifically in the “LocalState” folder.

Change Linux distro install drive on WSL using Import command

To move a Linux distro using the WSL import command, use these steps:

  1. Open Start.

  2. Search for Command Prompt, right-click the top result, and choose the Run as administrator option.

  3. Type the following command to view the distros already installed on your computer and press Enter:

    wsl --list --all
  4. Type the following command to shutdown any running distribution of Linux and press Enter:

    wsl --shutdown
  5. Type the following command to export a Linux distro and press Enter:

    wsl --export Kali-linux kali-export.tar

    In the command, change “Kali-linux” to the name of the distro you’re exporting and specify a name for the “.tar” file. The exported package will be available from the root of the “C” drive.

  6. Type the following command to remove the Linux instance from your computer and press Enter:

    wsl --unregister Kali-linux

    WSL export distro commands

    In the command, change “Ubuntu” of the distro you’re removing from the main system drive.

  7. Type the following command to import the WSL distro in the new location and press Enter:

    wsl --import Kali-linux F:\WSL\Kali-linux C:\kali-export.tar

    WSL import distro to new drive command

    In the command, change “Kali-linux” for the name of the distro, “F:\WSL\Kali-linux” for the new path to store the Linux distribution, and “C:\kali-export.tar” for the path and exported package name.

After you complete the steps, the WSL distribution will run from the new location.


Source link

Related Articles

Back to top button
close